package cn.com.cloudpioneer.evaluate.controller;

import cn.com.cloudpioneer.evaluate.model.ItemModel;
import cn.com.cloudpioneer.evaluate.model.UserModel;
import cn.com.cloudpioneer.evaluate.service.ItemService;
import cn.com.cloudpioneer.evaluate.utils.CustomException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther maruikai
 * @create 2023/9/13-9:45
 */
@RestController
@RequestMapping("/api/xgs/item")
@Api(tags = "项目管理")
public class ItemController extends BaseController {

    @Autowired
    private ItemService itemService;

    @RequestMapping(value = "/set", method = RequestMethod.POST)
    @ApiOperation(value = "添加/修改项目")
    public Object addWork(@RequestBody ItemModel workModel) throws CustomException {
        return itemService.setWork(workModel);
    }

    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @ApiOperation(value = "删除项目")
    public Object delWork(@RequestBody ItemModel workModel) throws CustomException {
        return itemService.delWork(workModel);
    }

    @RequestMapping(value = "/achieve", method = RequestMethod.POST)
    @ApiOperation(value = "归档项目")
    public Object achieveWork(@RequestBody ItemModel workModel) throws CustomException {
        return itemService.achieveWork(workModel);
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(value = "未评估项目列表")
    public Object getWorkList(@RequestParam(value = "keyword", defaultValue = "") String keyword,
                              @RequestParam("pageNo") int pageNo,
                              @RequestParam("pageSize") int pageSize) throws CustomException {
        UserModel userModel = super.verifyLogin();
        return itemService.getWorkList(keyword, userModel.getUserId(), pageNo, pageSize);
    }

    @RequestMapping(value = "/achieve_list", method = RequestMethod.POST)
    @ApiOperation(value = "已评估项目列表")
    public Object getAchieveList(@RequestParam(value = "keyword", defaultValue = "") String keyword,
                                 @RequestParam("pageNo") int pageNo,
                                 @RequestParam("pageSize") int pageSize) throws CustomException {
        UserModel userModel = super.verifyLogin();
        return itemService.getAchieveList(keyword, userModel.getUserId(), pageNo, pageSize);
    }

    @RequestMapping(value = "/item_info", method = RequestMethod.POST)
    @ApiOperation(value = "获取项目所有信息", response = ItemModel.class)
    public Object getItemInfo(@RequestParam String itemId) throws CustomException {
        return itemService.getItemInfo(itemId);
    }

}
